import { expect } from '@jest/globals';

import { initExecuteCommand, runHvigorAsync } from '../../common/common';
import {
  AbilityType,
  APIType,
  APIVersion,
  CaseLevel,
  IsEnable,
  LanguageType,
  ModuleTemplateType,
  RuntimeOSType,
  SDKType,
  SignType
} from '../../plugins/project-builder/models/constants';
import { TestCaseBuilder } from '../../plugins/task-builder/task-case-builder';
import { ProjectBuildOption, TestCaseFun } from '../../plugins/task-builder/test-case';
import { TestTaskOption } from '../../plugins/task-builder/test-task-option';

const projectBuilderOption: ProjectBuildOption = {
  template: {
    sdk: SDKType.Single,
    runtimeOS: RuntimeOSType.HarmonyOS,
    apiVersion: APIVersion.API10,
    apiType: APIType.STAGE,
    language: LanguageType.ArkTs,
    abilityType: AbilityType.Application,
    entryTemplateType: ModuleTemplateType.EmptyAbility
  },

  modulesOption: {
    [ModuleTemplateType.SharedLibrary]: 1,
  }
};

const taskConfig: TestTaskOption = {
  caseLevel: CaseLevel.L1,
  sign: SignType.NoSign,
  ohpmInstall: IsEnable.DisAble,
};

const testFun: TestCaseFun = async (project, taskConfig, record) => {
  // 测试工程主目录路径
  const projectRoot = project.projectRootPath();

  // 需要执行的命令行参数
  const commands = initExecuteCommand({
    mode: 'module',
    product: 'default',
    tasks: 'assembleHsp',
  });

  // 执行编译
  const result = await runHvigorAsync(projectRoot, commands);

  record.addStep('执行hsp编译构建', result);

  expect(result.stdout).toContain('BUILD SUCCESSFUL');

};

// 将demo测试用例注册到测试用例中心
TestCaseBuilder.builder()
  .caseName('OPEN_LAB_AIDE_ZOS_HOS_STAGE_Shared_Library_api10_001')
  .description('编译hsp模块')
  .projectBuilderOption(projectBuilderOption)
  .taskConfig(taskConfig)
  .testFun(testFun)
  .load();
